﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Routing;

using Owin;

namespace ERPStore.Web.Start
{
	public class PersistentConnectionConfig
	{
		public static void RegisterRoutes(RouteCollection routes)
		{
			var path = System.Web.HttpRuntime.BinDirectory;
			var config = new Microsoft.AspNet.SignalR.ConnectionConfiguration();

			var connectionTypeList = from file in System.IO.Directory.GetFiles(path, "*.dll", System.IO.SearchOption.TopDirectoryOnly)
									 let asm = System.Reflection.Assembly.LoadFrom(file)
									 where asm.FullName.IndexOf("ERPStore.") != -1
									 from type in asm.GetTypes()
									 where type.IsSubclassOf(typeof(Microsoft.AspNet.SignalR.PersistentConnection))
									 select type;

			foreach (var item in connectionTypeList)
			{
				var url = string.Format("/realtime/{0}", item.Name.Replace("Connection", ""));
				// routes.MapSignalR(url, item, config);
			}
		}
	}
}
